using System.Collections.Generic;
using UnityEngine;

public class CompetitorCard : MonoBehaviour
{
	public UILabel nameLabel;

	public UISprite flagSprite;

	public GameObject statsLabelPrefab;

	public UIWidget widgetPanel;

	public int paddingx;

	public int paddingy;

	protected List<StatsLabel> stats = new List<StatsLabel>();

	public void Init(string name, int flag, SkillProvider skillProvider, SkillProvider opponentSkillProvider)
	{
		nameLabel.text = name;
		GameConstants.SetFlag(flagSprite, flag);
		int num = 0;
		int num2 = 1;
		Vector3[] localCorners = widgetPanel.localCorners;
		Vector3 vector = localCorners[0] + widgetPanel.cachedTransform.localPosition;
		foreach (StatsLabel stat in stats)
		{
			stat.gameObject.SetActive(false);
		}
		PlayerStatsManager.SkillType[] displaySkills = skillProvider.displaySkills;
		for (int i = 0; i < displaySkills.Length; i++)
		{
			PlayerStatsManager.SkillType skillTypeIndex = displaySkills[i];
			StatsLabel statsLabel = null;
			if (num >= stats.Count)
			{
				stats.Add(NGUITools.AddChild(base.gameObject, statsLabelPrefab).GetComponent<StatsLabel>());
			}
			statsLabel = stats[num];
			statsLabel.nameLabel.text = skillTypeIndex.ToString() + ": ";
			float skillValue = skillProvider.GetSkillValue((int)skillTypeIndex);
			float progress = skillValue - (float)Mathf.FloorToInt(skillValue);
			statsLabel.valueLabel.text = Mathf.FloorToInt(skillValue).ToString();
			statsLabel.skillProgress.UpdateSlider(progress);
			Color color = Color.white;
			if (skillProvider.GetSkillValue((int)skillTypeIndex) > opponentSkillProvider.GetSkillValue((int)skillTypeIndex))
			{
				color = Color.green;
			}
			else if (opponentSkillProvider.GetSkillValue((int)skillTypeIndex) > skillProvider.GetSkillValue((int)skillTypeIndex))
			{
				color = Color.red;
			}
			statsLabel.valueLabel.color = color;
			statsLabel.gameObject.SetActive(true);
			UIWidget component = statsLabel.GetComponent<UIWidget>();
			Vector2 localSize = component.localSize;
			Vector3 localPosition = component.cachedTransform.localPosition;
			localPosition.x = vector.x + ((float)(num % num2) + component.pivotOffset.x) * localSize.x + (float)((num % num2 + 1) * paddingx);
			localPosition.y = vector.y - ((float)(num / num2) + component.pivotOffset.y) * localSize.y - (float)((num / num2 + 1) * paddingy);
			component.cachedTransform.localPosition = localPosition;
			num++;
		}
	}
}
